package com.yunxi.controller.sto;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sto.pojo.StoCarriageRouteVO;
import com.yunxi.sto.service.StoCarriageRouteDubboService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 运输路线 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-05-15
 */
@RestController
@RequestMapping("/admin/stoCarriageRoute")
@Api(tags = "sto:carriageRoute", description = "运输路线接口")
public class StoCarriageRouteController {
 private static final Logger logger = LoggerFactory.getLogger(StoCarriageRouteController.class);

 @Autowired
 StoCarriageRouteDubboService stoCarriageRouteDubboService;

 @GetMapping("/page")
 @ApiOperation(value = "查询分页")
 @ApiImplicitParams({
         @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
         @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
 })
 public ApiResult page(StoCarriageRouteVO stoCarriageRouteVO,Integer pageNum,Integer pageSize) throws Exception {
  return ResponseUtil.ok(stoCarriageRouteDubboService.findPageByVO(stoCarriageRouteVO, pageNum, pageSize));
 }

 @GetMapping("/load")
 @ApiOperation(value = "读取单个")
 @ApiImplicitParam(paramType="query", name = "routeId", value = "主键id", required = true, dataType = "String")
 public ApiResult load(String routeId, @CurrentUser LoginInfo loginInfo) throws Exception {
  return ResponseUtil.ok(stoCarriageRouteDubboService.getById(routeId));
 }

 @PostMapping("/save")
 @ApiOperation(value = "保存信息")
 public ApiResult save(@RequestBody StoCarriageRouteVO stoCarriageRouteVO, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoCarriageRouteVO.setCreateBy(loginInfo.getUserCode());
  stoCarriageRouteVO.setUpdateBy(loginInfo.getUserCode());
  stoCarriageRouteDubboService.saveOrUpdate(stoCarriageRouteVO);
  return ResponseUtil.ok("success");
 }

 @PostMapping("/del")
 @ApiOperation(value = "作废")
 public ApiResult del(@RequestBody @ApiParam(value = "主键id集合") List<String> list, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoCarriageRouteDubboService.del(list,loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

 @PostMapping("/reset")
 @ApiOperation(value = "恢复")
 public ApiResult reset(@RequestBody @ApiParam(value = "主键id集合") List<String> list, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoCarriageRouteDubboService.reset(list,loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

 @PostMapping("/approve")
 @ApiOperation(value = "审批")
 public ApiResult approve(@RequestBody @ApiParam(value = "路线审核对象集合") List<StoCarriageRouteVO> list, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoCarriageRouteDubboService.approve(list,loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

 @GetMapping("/list")
 @ApiOperation(value = "获取路线列表")
 public ApiResult list() throws Exception {
  return ResponseUtil.ok(stoCarriageRouteDubboService.list());
 }

 @GetMapping("/carrierList")
 @ApiOperation(value = "获取承运商列表")

 @ApiImplicitParams({
         @ApiImplicitParam(value = "路线主键id",name = "routeId",dataType = "String",paramType = "query"),
         @ApiImplicitParam(value = "发运方式key",name = "carriageType",dataType = "String",paramType = "query")
 })
 public ApiResult carrierList(String routeId,String carriageType) throws Exception {
  return ResponseUtil.ok(stoCarriageRouteDubboService.carrierList(routeId,carriageType));
 }


}
